package com.lh.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.lh.entity.table.RectificationInfo;
import com.lh.entity.vo.DeadlineNodeOutput;
import com.lh.service.RectificationInfoService;
import com.lh.utils.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * 整改接口
 */
@RestController
@RequestMapping("/rectification")
public class RectificationInfoController {

    @Autowired
    private RectificationInfoService rectificationInfoService;

    @RequestMapping("/add")
    public Answer<Object> add(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.add(rectificationInfo);
    }

    @RequestMapping("/checkName")
    public Answer<Object> checkName(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.checkName(rectificationInfo);
    }


    @RequestMapping("/addRectification")
    public Answer<Object> addRectification(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.addRectification(rectificationInfo);
    }

    @RequestMapping("/getRectificationList")
    public Answer<Object> getRectificationList(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.getRectificationList(reqJson);
    }

    @RequestMapping("/updateRectification")
    public Answer<Object> updateRectification(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.updateRectification(rectificationInfo);
    }

    @RequestMapping("/AddDeadlineNode")
    public Answer<Object> AddDeadlineNode(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.AddDeadlineNode(reqJson);
    }

    @RequestMapping("/deleteItem")
    public Answer<Object> deleteItem(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.deleteItem(reqJson.getInteger("id"));
    }

    // 分配
    @RequestMapping("/distribute")
    public Answer<Object> distribute(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.distribute(reqJson);
    }

    @RequestMapping("/queryDeadlineNodeList")
    public Answer<Object> queryDeadlineNodeList(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.queryDeadlineNodeList(rectificationInfo);
    }

    @RequestMapping("/queryDistributeDeadlineNodeList")
    public Answer<Object> queryDistributeDeadlineNodeList(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.queryDistributeDeadlineNodeList(rectificationInfo);
    }

    // 分配确认
    @RequestMapping("/issueConfirmation")
    public Answer<Object> issueConfirmation(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.issueConfirmation(rectificationInfo);
    }


    @RequestMapping("/queryRectificationList")
    public Answer<Object> queryRectificationList(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.queryRectificationList(rectificationInfo);
    }

    @RequestMapping("/queryDirTreeByType")
    public Answer<Object> queryDirTreeByType(@RequestBody JSONObject reqJson) {
        String type = reqJson.getString("type");
        if (StrUtil.isEmpty(type)){
            type = "type";
        }
        return rectificationInfoService.queryDirTreeByType(type);
    }

    @RequestMapping("/queryDirTreeByTypeAll")
    public Answer<Object> queryDirTreeByTypeAll(@RequestBody JSONObject reqJson) {
        String type = reqJson.getString("type");
        String departmentName = reqJson.getString("departmentName");
        String leadUnit = reqJson.getString("leadUnit"); // 牵头单位
        if (StrUtil.isEmpty(type)){
            type = "type";
        }
        return rectificationInfoService.queryDirTreeByTypeAll(type,departmentName,leadUnit);
    }

    //根据当前部门查树
    @RequestMapping("/queryDirTreeType")
    public Answer<Object> queryDirTreeType(@RequestBody JSONObject reqJson) {
        String currentDepartment = reqJson.getString("currentDepartment");
        return rectificationInfoService.queryDirTreeType(currentDepartment);
    }


    @RequestMapping("/queryRectificationListV2")
    public Answer<Object> queryRectificationListV2(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.queryRectificationListV2(rectificationInfo);
    }

    @RequestMapping("/queryRectificationPageV2")
    public Answer<Object> queryRectificationPageV2(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.queryRectificationPageV2(reqJson);
    }

    // 计算已经完成的数和红绿灯数量
    @RequestMapping("/queryRectificationStaticV2")
    public Answer<Object> queryRectificationStaticV2(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.queryRectificationStaticV2(rectificationInfo);
    }


    /**
     * 责任部门查询项目
     * @param jsonObject
     * @return
     */
    @RequestMapping("/queryRectificationPage")
    public Answer<Object> queryRectificationPage(@RequestBody JSONObject jsonObject) {
        return rectificationInfoService.queryRectificationPage(jsonObject);
    }

    @RequestMapping("/selectDepartmentNameList")
    public Answer<Object> selectDepartmentNameList() {
        return rectificationInfoService.selectDepartmentNameList();
    }

    @RequestMapping("/getLinkTotal")
    public Answer<String> getLinkTotal() {
        return rectificationInfoService.getLinkTotal();
    }



    @RequestMapping("/exportDeadlineByMainId")
    public void exportDeadlineByMainIdGet(@RequestParam Integer mainId, HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        req.setMainId(mainId);
        rectificationInfoService.exportDeadlineByMainId(req, response);
    }

    /**
     * 导出任务管理
     * @param reqJson
     * @param response
     */
    @RequestMapping("/exportRectificationManagement")
    public void exportRectificationManagement(@RequestBody JSONObject reqJson, HttpServletResponse response) {
        rectificationInfoService.exportRectificationManagement(reqJson, response);
    }

    /**
     * 导出统计分析
     * @param reqJson
     * @param response
     */
    @RequestMapping("/exportRectificationList")
    public void exportRectificationList(@RequestBody JSONObject reqJson, HttpServletResponse response) {
        rectificationInfoService.exportRectificationList(reqJson, response);
    }


    @RequestMapping("/groupByTitle")
    public Answer<Object> groupByTitle() {
        return rectificationInfoService.groupByTitle();
    }

    @RequestMapping("/groupByPersonLiaible")
    public Answer<Object> groupByPersonLiaible() {
        return rectificationInfoService.groupByPersonLiaible();
    }

    @RequestMapping("/groupByDepartment")
    public Answer<Object> groupByDepartment() {
        return rectificationInfoService.groupByDepartment();
    }

    @RequestMapping("/groupByLeadLeader")
    public Answer<Object> groupByLeadLeader() {
        return rectificationInfoService.groupByLeadLeader();
    }

    @RequestMapping("/groupByCurrentNode")
    public Answer<Object> groupByCurrentNode() {
        return rectificationInfoService.groupByCurrentNode();
    }

    @RequestMapping("/getRectificationInfoByLike")
    public Answer<Object> getRectificationInfoByLike(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.getRectificationInfoByLike(rectificationInfo);
    }

    @RequestMapping("/queryRectificationV2Num")
    public Answer<Object> queryRectificationV2Num() {
        return rectificationInfoService.queryRectificationV2Num();
    }


    /**
     * 数的最新生成方式
     * @return
     */
    @RequestMapping("/queryRectificationTreeNew")
    public Answer<Object> queryRectificationTreeNew(@RequestBody JSONObject reqJson) {
        String type = reqJson.getString("type");
        String departmentName = reqJson.getString("departmentName");
        String zerenDepartment = reqJson.getString("zerenDepartment");
        Integer warnLevel = reqJson.getInteger("warnLevel");
        if (type.equals("type")){
            return rectificationInfoService.groupByType(departmentName,warnLevel,zerenDepartment);
        }else if (type.equals("area")){
            return rectificationInfoService.groupByArea(departmentName,warnLevel,zerenDepartment);
        }else if (type.equals("department")){
            return rectificationInfoService.groupByDepartment(departmentName,warnLevel,zerenDepartment);
        }else{
            return Answer.error("类型错误");
        }
    }


    @RequestMapping("/queryCurrentRectificationTreeType")
    public Answer<Object> queryCurrentRectificationTreeType(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.groupNodeDepartmentType(reqJson);
    }

    /**
     * 市直部门统计
     * @return
     */
    @RequestMapping("/queryRectificationV2NumCity")
    public Answer<Object> queryRectificationV2NumCity() {
        return rectificationInfoService.queryRectificationV2NumCity();
    }


    /**
     * 节点统计分析
     * 冯志奇
     * @return
     */
    @RequestMapping("/queryRectificationNodeCity")
    public Answer<Object> queryRectificationNodeCity() {
        return rectificationInfoService.queryRectificationNodeCity();
    }

    @RequestMapping("/queryRectificationV2ProjectType")
    public Answer<Object> queryRectificationV2ProjectType(@RequestBody RectificationInfo rectificationInfo) {
        return rectificationInfoService.queryRectificationV2ProjectType(rectificationInfo);
    }

    @RequestMapping("/queryStaticAllScreen")
    public Answer<Object> queryStaticAllScreen() {
        return rectificationInfoService.queryStaticAllScreen();
    }


    @RequestMapping("/rectificationAnalyzeByPeople")
    public Answer<Object> rectificationAnalyzeByPeople() {
        return rectificationInfoService.rectificationAnalyzeByPeople();
    }

    @RequestMapping("/rectificationAnalyzeByPeople2")
    public Answer<Object> rectificationAnalyzeByPeople2() {
        return rectificationInfoService.rectificationAnalyzeByPeople2();
    }


    @RequestMapping("/rectificationAnalyzeByArea")
    public Answer<Object> rectificationAnalyzeByArea() {
        return rectificationInfoService.rectificationAnalyzeByArea();
    }


    /**
     * 重点工作督办落实统计分析（按县市区分）
     * 杨启涛
     * @return
     */
    @RequestMapping("/rectificationAnalyzeByStreet")
    public Answer<Object> rectificationAnalyzeByStreet() {
        return rectificationInfoService.rectificationAnalyzeByStreet();
    }

    /**
     * 重点工作督办落实统计分析（按市直牵头部门分）
     * 杨启涛
     * @return
     */
    @RequestMapping("/rectificationAnalyzeByCity")
    public Answer<Object> rectificationAnalyzeByCity() {
        return rectificationInfoService.rectificationAnalyzeByCity();
    }

    /**
     * 重点工作督办落实统计分析（按具体环节分）
     * 杨启涛
     * @return
     */
    @RequestMapping("/rectificationDeadlineAnalyzeByCity")
    public Answer<Object> rectificationDeadlineAnalyzeByCity() {
        return rectificationInfoService.rectificationDeadlineAnalyzeByCity();
    }

    /**
     * 重点工作督办落实统计分析（按类别分）
     * 杨启涛
     * @return
     */
    @RequestMapping("/rectificationAnalyze")
    public Answer<Object> rectificationAnalyze() {
        return rectificationInfoService.rectificationAnalyze();
    }

    @RequestMapping("/getRectificationInfoXF")
    public Answer<Object> getRectificationInfoXF() {
        return rectificationInfoService.getRectificationInfoXF();
    }

    @RequestMapping("/getRectificationInfoById")
    public Answer<Object> getRectificationInfoById(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.getRectificationInfoById(reqJson);
    }

    @RequestMapping("/getRectificationListByDeadLine")
    public Answer<Object> getRectificationListByDeadLine() {
        return rectificationInfoService.getRectificationListByDeadLine();
    }

    @RequestMapping("/getRectificationListByUpdateDeadline")
    public Answer<Object> getRectificationListByUpdateDeadline(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.getRectificationListByUpdateDeadline(reqJson);
    }

    @RequestMapping("/countLightByStreet")
    public Answer<Object> countLightByStreet() {
        return rectificationInfoService.countLightByStreet();
    }

    @RequestMapping("/countLightByOrganization")
    public Answer<Object> countLightByOrganization() {
        return rectificationInfoService.countLightByOrganization();
    }

    @RequestMapping("/countLight")
    public Answer<Object> countLight(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.countLight(reqJson);
    }

    @RequestMapping("/lightRectification")
    public Answer<Object> lightRectification(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.lightRectification(reqJson);
    }

    @RequestMapping("/exportCountLightByStreet")
    public void exportCountLightByStreet(HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountLightByStreet(req, response);
    }

    @RequestMapping("/exportCountLightByOrganization")
    public void exportCountLightByOrganization(HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountLightByOrganization(req, response);
    }

    @RequestMapping("/exportCountLight")
    public void exportCountLight(HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountLight(req, response);
    }

    @RequestMapping("/exportLightRectification")
    public void exportLightRectification(HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportLightRectification(req, response);
    }

    @RequestMapping("/countAmount")
    public Answer<Object> countAmount(@RequestBody JSONObject reqJson) {
        String projectStatus = reqJson.getString("projectStatus");
        return rectificationInfoService.countAmount(projectStatus);
    }

    @RequestMapping("/countAmountInvestment")
    public Answer<Object> countAmountInvestment(@RequestBody JSONObject reqJson) {
        String projectStatus = reqJson.getString("projectStatus");
        return rectificationInfoService.countAmountInvestment(projectStatus);
    }

    @RequestMapping("/countAmountBefore")
    public Answer<Object> countAmountBefore(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.countAmountBefore(reqJson);
    }

    @RequestMapping("/exportCountAmount")
    public void exportCountAmount(@RequestBody JSONObject reqJson,HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountAmount(req, response,reqJson);
    }

    @RequestMapping("/exportCountAmountInvestment")
    public void exportCountAmountInvestment(@RequestBody JSONObject reqJson,HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountAmountInvestment(req, response,reqJson);
    }

    @RequestMapping("/exportCountAmountBefore")
    public void exportCountAmountBefore(@RequestBody JSONObject reqJson,HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountAmountBefore(req, response,reqJson);
    }

    @RequestMapping("/countAmountDetails")
    public Answer<Object> countAmountDetails(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.countAmountDetails(reqJson);
    }

    @RequestMapping("/rectificationDetails")
    public Answer<Object> rectificationDetails(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.rectificationDetails(reqJson);
    }

    @RequestMapping("/exportRectificationDetails")
    public void exportRectificationDetails(@RequestBody JSONObject reqJson,HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportRectificationDetails(req, response,reqJson);
    }

    @RequestMapping("/deadlineRed")
    public Answer<Object> deadlineRed() {
        return rectificationInfoService.deadlineRed();
    }

    @RequestMapping("/exportDeadlineRed")
    public void exportDeadlineRed(HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportDeadlineRed(req, response);
    }

    @RequestMapping("/countRedLight")
    public Answer<Object> countRedLight() {
        return rectificationInfoService.countRedLight();
    }

    @RequestMapping("/exportCountRedLight")
    public void exportCountRedLight(HttpServletResponse response) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportCountRedLight(req, response);
    }

    @RequestMapping("/terminationRectification")
    public Answer<Object> terminationRectification(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.terminationRectification(reqJson);
    }

    @RequestMapping("/exportTerminationRectification")
    public void exportTerminationRectification(HttpServletResponse response,@RequestBody JSONObject reqJson) {
        DeadlineNodeOutput req = new DeadlineNodeOutput();
        rectificationInfoService.exportTerminationRectification(req, response,reqJson);
    }

    /**
     * 今天情况统计
     * @param reqJson
     * @return
     */
    @RequestMapping("/getTodayUpdate")
    public Answer<Object> getTodayUpdate(@RequestBody JSONObject reqJson) {
        return rectificationInfoService.getTodayUpdate(reqJson);
    }

    /**
     * 超时统计
     * @return
     */
    @RequestMapping("/getOverdueLink")
    public Answer<Object> getOverdueLink() {
        return rectificationInfoService.getOverdueLink();
    }
}
